<?php

namespace App\Services;

use App\Repository\Contracts\RoleRepository;
use App\Repository\Contracts\PermissionRepository;

class RoleService
{
    /**
     * @var RoleRepositoryEloquent
     */
    protected $roleRepository;
    /**
     * @var PermissioRepositoryEloquent
     */
    protected $permissionRepository;

    public function __construct(RoleRepository $roleRepository, PermissionRepository $permissionRepository)
    {
        $this->roleRepository = $roleRepository;
        $this->permissionRepository = $permissionRepository;
    }


    /**
    * Get Menus  and paginate.
    *
    * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
    */
    public function getRoles()
    {

        return $this->roleRepository->paginate(10);
    }

    public function storeRoles($data)
    {
        $data['guard_name'] = 'admin';
        return $this->roleRepository->createRole($data);
    }


    public function showRole($id)
    {
        return $this->roleRepository->toEntity()->with('permissions')->find($id);
    }


<<<<<<< HEAD
}
=======
    public function updateRoles($id, $data)
    {
        $permissions = $data['permission'];
        unset($data['permission']);

        $role = $this->roleRepository->find($id);
        $role->syncPermissions($permissions);

        return $this->roleRepository->update($id, $data);
    }



}
>>>>>>> permission
